(*
	SPortConfiguration() -- Returns a string containing the current configuration of the port. The string
		is in the same format as the parameters passed to configureSPort.

	To compile and link this file using Macintosh Programmer's Workshop,

		pascal -w SPortConfiguration.p
		link -m ENTRYPOINT -o HyperCommands -rt XFCN=7036 -sn Main=SPortConfiguration ¶
			SPortConfiguration.p.o "{MPW}"Libraries:interface.o "{MPW}"PLibraries:PasLib.o

	© Copyright 1987,88 by Apple Computer, Inc.

	Initial coding 9/87 by Harry R. Chesley.
*)

{$R-}

{$S SPortConfiguration } 	{ Segment name must be the same as the command name. }

unit DummyUnit;

interface

uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;

procedure EntryPoint(paramPtr: XCmdPtr);
	
implementation

type

Str31 = String[31];

procedure SPortConfiguration(paramPtr: XCmdPtr); forward;

procedure EntryPoint(paramPtr: XCmdPtr);

	begin
		SPortConfiguration(paramPtr);
	end;

procedure SPortConfiguration(paramPtr: XCmdPtr);

	var theConfiguration: str255;
		i: integer;

	{$I XCmdGlue.inc}

	procedure Fail(errMsg: Str255); { set theResult and quit }
		begin
			paramPtr^.returnValue := PasToZero(errMsg);
			exit(SPortConfiguration);
		end;

	{$I SPortUtil.inc}

	procedure concatStr(str: str255);

		begin
			theConfiguration := Concat(theConfiguration,str);
		end;

	procedure concatOnOff(name: str255; onOff: boolean);

		begin
			concatStr(',');
			concatStr(name);
			if onOff then concatStr('On')
			else concatStr('Off');
		end;

	begin
		if paramPtr^.paramCount <> 0 then Fail('parameter count is not 0');

		SetUpSPortGlobals;

		{ Start with the port: }
		if Globals^^.selectedPort = sPortA then theConfiguration := 'modemPort'
		else theConfiguration := 'printerPort';

		with ThisSPort do
			begin
				{ Add in the baud rate: }
				case BitAnd(byteConfig,$3FF) of
					baud300: concatStr(',baud300');
					baud600: concatStr(',baud600');
					baud1200: concatStr(',baud1200');
					baud1800: concatStr(',baud1800');
					baud2400: concatStr(',baud2400');
					baud3600: concatStr(',baud3600');
					baud4800: concatStr(',baud4800');
					baud7200: concatStr(',baud7200');
					baud9600: concatStr(',baud9600');
					baud19200: concatStr(',baud19200');
					baud57600: concatStr(',baud57600');
					end;

				{ And the stop bits: }
				{ This is what the following code should look like, but the compile doesn't seem to be able to handle it:
							case integer(BitAnd(byteConfig,$0C000)) of
								stop10: concatStr(',stop10');
								stop15: concatStr(',stop15');
								stop20: concatStr(',stop20');
								end;}
				i := BitAnd(byteConfig,$0C000);
				if i = stop10 then concatStr(',stop10')
				else if i = stop15 then concatStr(',stop15')
				else if i = stop20 then concatStr(',stop20');

				{ And the parity: }
				case integer(BitAnd(byteConfig,$03000)) of
					noParity: concatStr(',parityOff');
					oddParity: concatStr(',parityOdd');
					evenParity: concatStr(',parityEven');
					end;

				{ And the number of data bits: }
				case integer(BitAnd(byteConfig,$00C00)) of
					data5: concatStr(',data5');
					data6: concatStr(',data6');
					data7: concatStr(',data7');
					data8: concatStr(',data8');
					end;

				{ And flow control: }
				concatOnOff('XOnOut',shakes.fXOn <> 0);
				concatOnOff('CTSOut',shakes.fCTS <> 0);

				{ Misc. control parameters: }
				concatOnOff('linefeed',sendLFs);
				concatOnOff('echo',doEcho);
				concatOnOff('edit',doEdit);
				concatOnOff('strip',stripIncoming);
				concatOnOff('stripControls',stripControls);
				concatOnOff('autoWrap',autoWrap);
			end;

		{ Return the complete configuration. }
		paramPtr^.returnValue := PasToZero(theConfiguration);
	end;
end.
